<template>
  <div class="classify">
    <van-nav-bar
      title="狗狗主粮"
      left-arrow
      @click-left="onClickLeft"
      @click-right="onClickRight"
    >
      <template #right>
        <van-icon name="search" size="18" />
      </template>
    </van-nav-bar>
    <div class="tothird">
      <van-grid :column-num="5">
        <van-grid-item
          v-for="(item, index) in arr"
          :key="index"
          @click="goClick()"
        >
          <img :src="item.imgurl" />
          <p>{{ item.title }}</p>
        </van-grid-item>
      </van-grid>
    </div>
    <van-cell title="口碑推荐" is-link to="" />
    <ul class="praise">
      <li>
        <img src="../../assets/img/mine/15.webp" />
        <p>进口狗粮</p>
        <span>¥759</span>
      </li>
      <li>
        <img src="../../assets/img/mine/15.webp" />
        <p>进口狗粮</p>
        <span>¥759</span>
      </li>
      <li>
        <img src="../../assets/img/mine/15.webp" />
        <p>进口狗粮</p>
        <span>¥759</span>
      </li>
      <li>
        <img src="../../assets/img/mine/15.webp" />
        <p>进口狗粮</p>
        <span>¥759</span>
      </li>
    </ul>
    <van-cell title="热购优惠" />
    <ul class="hot">
      <li>
        <img src="../../assets/img/mine/15.webp" />
        <p>进口狗粮</p>
        <span>¥759</span>
      </li>
      <li>
        <img src="../../assets/img/mine/15.webp" />
        <p>进口狗粮</p>
        <span>¥759</span>
      </li>
      <li>
        <img src="../../assets/img/mine/15.webp" />
        <p>进口狗粮</p>
        <span>¥759</span>
      </li>
      <li>
        <img src="../../assets/img/mine/15.webp" />
        <p>进口狗粮</p>
        <span>¥759</span>
      </li>
    </ul>

    <div class="sort">
      <span :class="{ active: active == 1 }" @click="change(0)">综合</span>
      <span :class="{ active: active == 0 }" @click="change(1)">价格</span>
    </div>
    <ul class="sort_content clearfix">
      <li class="clone">
        <div class="clone_img"></div>
        <p class="clone_title">比乐 真谷粒全期犬粮磨牙洁齿美毛泰迪通用</p>
        <p class="clone_msg">低敏无谷配方完善骨骼肌肉发育骨粉颗粒</p>
        <p class="clone_price">¥100{{}}</p>
      </li>
      <li class="clone">
        <div class="clone_img"></div>
        <p class="clone_title">比乐 真谷粒全期犬粮磨牙洁齿美毛泰迪通用</p>
        <p class="clone_msg">低敏无谷配方完善骨骼肌肉发育骨粉颗粒</p>
        <p class="clone_price">¥100{{}}</p>
      </li>
    </ul>
    <!-- <VirtualCollection
      :cellSizeAndPositionGetter="cellSizeAndPositionGetter"
      :collection="items"
      :height="500"
      :width="330"
    >
      <div slot="cell" slot-scope="props">{{props.data}}</div>
      <li v-for="(item, index) in items" :key="index"></li>
    </VirtualCollection> -->
    <button @click="handleClick">点我</button>
    <div class="classify_footer"></div>
  </div>
</template>

<script>
import { ref, onMounted } from "vue";
import http from "../../utils/api";
import router from "@/router/index.js";
export default {
  setup() {
    const active = ref(1);
    const arr = ref();
    onMounted(() => {
      http.ClassifyApi().then((res) => {
        console.log(res.data);
        arr.value = res.data.data.classify;
        console.log(arr.value);
      });
    });
    const goClick = ref(function () {
      router.push("/productlist/" + "狗狗主粮_进口狗粮");
    });
    // const items = [Array.from({length: 10}, (_, index) => ({ data: '#' + index }))];
    // const items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
    return {
      active,
      arr,
      goClick,
    };
  },
  methods: {
    onClickLeft() {
      router.go(-1);
    },
    onClickRight() {},
    change(num) {
      if (num == 1) {
        this.active = 0;
      } else {
        this.active = 1;
      }
    },
  },
};
</script>
<style lang="less" scoped>
.classify {
  width: 100%;
  .tothird {
    width: 357px;
    margin: 9px;
    border-radius: 5px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    text-align: center;
    img {
      width: 50px;
      height: 50px;
    }
    p {
      width: 50px;
      margin-top: 5px;
      font-size: 10px;
    }
  }
  .van-cell {
    background-color: #c48f8f;
    color: #fff;
    width: 365px;
    height: 42px;
    border-radius: 5px 5px 0 0;
    margin: 0 auto;
    ::before {
      color: #fff;
    }
  }
  .praise,
  .hot {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-evenly;
    width: 365px;
    height: 168px;
    margin: 0 auto;
    border-radius: 0 0 5px 5px;
    background-color: #fff;
    margin-bottom: 10px;
    li {
      height: 168px;
      display: flex;
      flex-direction: column;
      justify-content: space-evenly;
      align-items: center;
    }
    img {
      width: 50px;
      height: 50px;
    }
    p {
      font-size: 12px;
    }
    span {
      font-size: 13px;
      color: red;
    }
  }
  .sort {
    width: 100%;
    height: 35px;
    padding: 25px;
    background-color: #fff;
    color: grey;
    font-size: 14px;
    padding: 0 50px;
    span {
      margin-right: 25px;
      line-height: 35px;
    }
    .active {
      color: black;
    }
  }
  .clearfix::after {
    content: ".";
    display: block;
    height: 0;
    overflow: hidden;
    visibility: hidden;
    clear: both;
  }
  .sort_content {
    width: 100%;
    .clone {
      width: 176px;
      margin: 5px;
      float: left;
      background-color: #fff;
      .clone_img {
        width: 176px;
        height: 180px;
        background-color: #000;
      }
      .clone_title {
        font-size: 15px;
        text-align: center;
        line-height: 21px;
        padding: 0 10px;
      }
      .clone_msg {
        font-size: 14px;
        color: grey;
        line-height: 19px;
        padding: 0 10px;
      }
      .clone_price {
        font-size: 13px;
        color: red;
        margin: 10px;
      }
    }
  }
  .classify_footer {
    width: 100%;
    height: 200px;
  }
}
</style>
